package com.wcl.nullmusic.ui.adapter;

import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.wcl.nullmusic.R;
import com.wcl.nullmusic.mode.Recommend_CategoryContents_List_List;
import com.wcl.nullmusic.ui.activity.AnthologyActivity;
import com.wcl.nullmusic.utils.ToActivityUtils;

import java.util.List;

/**
 * Created by dllo on 16/1/17.
 */
public class RankingRecyclerViewAdapter extends RecyclerView.Adapter<RankingRecyclerViewAdapter.ViewHolder> {

    private static final int TYPE0 = 0;
    private static final int TYPE1 = 1;
    private static final int TYPE2 = 2;
    private static final int TYPE3 = 3;
    private List<Recommend_CategoryContents_List_List> datas;
    private Context context;

    public RankingRecyclerViewAdapter(Context context) {
        this.context = context;
    }

    public void addData(List<Recommend_CategoryContents_List_List> datas) {
        this.datas = datas;
        notifyDataSetChanged();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.ranking_recycler_item, null);
        return new ViewHolder(view);
    }

    @Override
    public int getItemViewType(int position) {
        switch (position) {
            case 0:
                return TYPE0;
            case 1:
                return TYPE1;
            case 2:
                return TYPE2;
            default:
                return TYPE3;
        }
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
    //    if (datas != null && datas.size() > 0) {
            final Recommend_CategoryContents_List_List contents_list_list = datas.get(position);
            holder.ranging_recycler_title.setText(contents_list_list.getNickname());
            holder.ranging_recycler_subTitle.setText(contents_list_list.getIntro());
            holder.ranging_recycler_counts.setText(contents_list_list.getTracksCounts() + "集");
            holder.ranging_recycler_rank.setText(position + 1 + "");
            switch (getItemViewType(position)) {
                case TYPE0:
                    holder.ranging_recycler_rank.setTextColor(Color.RED);
                    break;
                case TYPE1:
                    holder.ranging_recycler_rank.setTextColor(0xffff8800);
                    break;
                case TYPE2:
                    holder.ranging_recycler_rank.setTextColor(0xff99cc00);
                    break;
                case TYPE3:
                    holder.ranging_recycler_rank.setTextColor(0x80323232);
                    break;
            }

            Picasso.with(context).load(contents_list_list.getCoverMiddle()).placeholder(R.mipmap.ic_classify_img08).error(R.mipmap.ic_classify_img08)
                    .into(holder.ranging_recycler_pic);

            holder.ranging_recycler_layout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Bundle bundle = new Bundle();
                    bundle.putString("album", contents_list_list.getAlbumId() + "");
                    bundle.putString("position", 2 + "");
                    bundle.putString("title", contents_list_list.getTitle());
                    ToActivityUtils.startToActivity(context, AnthologyActivity.class, bundle);
                }
            });

       // }

    }

    @Override
    public int getItemCount() {
        return datas != null && datas.size() > 0 ? datas.size() : 0;
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        private RelativeLayout ranging_recycler_layout;
        private TextView ranging_recycler_rank, ranging_recycler_title, ranging_recycler_subTitle, ranging_recycler_counts;
        private ImageView ranging_recycler_pic;

        public ViewHolder(View itemView) {
            super(itemView);
            ranging_recycler_layout = (RelativeLayout) itemView.findViewById(R.id.ranging_recycler_layout);
            ranging_recycler_rank = (TextView) itemView.findViewById(R.id.ranging_recycler_rank);
            ranging_recycler_title = (TextView) itemView.findViewById(R.id.ranging_recycler_title);
            ranging_recycler_subTitle = (TextView) itemView.findViewById(R.id.ranging_recycler_subTitle);
            ranging_recycler_counts = (TextView) itemView.findViewById(R.id.ranging_recycler_counts);
            ranging_recycler_pic = (ImageView) itemView.findViewById(R.id.ranging_recycler_pic);
        }
    }

}



